Skip to content

feat(output-filter): collapse pytest progress lines and preserve failure root-cause headers - #104

Merged
INK-Q merged 2 commits into
INK-Q:devfrom
lnb-git:feat/pytest-output-filter
Nov 29, 2026
Merged

INK-Q merged 2 commits into
INK-Q:devfrom
lnb-git:feat/pytest-output-filter

Conversation

@lnb-git

@lnb-git lnb-git commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

  • Collapse contiguous passing pytest verbose lines (path/to/test.py::test_name[params] PASSED [ 10%], including Windows drive letters, spaced/single-nested [...] params, and domain-word filenames) and per-file passing dot-progress lines (tests/test_a.py . [10%], tests/test_error_handling.py .... [50%]) under GREEN_BUILD_OR_PASS_PATTERNS and UNAMBIGUOUS_TEST_PASS_PATTERNS while never folding failure verdicts (FAILED, ..F., .E).
  • Preserve pytest root-cause headers (^=== FAILURES ===$, ^=== ERRORS ===$, and case-sensitive ^E\s{2,}(?:assert\b|(?:[A-Za-z_][\w.]*)?(?:Error|Exception)(?:Group)?\b)) under tight output budgets via isRootCauseHeaderLine.
  • Add unit tests in test/output-filter.test.ts covering verbose/dot pass folding, Windows paths, generalized root-cause headers, negative non-root cases, and linear-time adversarial inputs (unbalanced brackets and repeated .py::).

Verification

  • npm run typecheck
  • npm run build && git diff --exit-code -- dist/
  • sh -n install.sh
  • npm test (212/212 passed)
  • npm run validate

@INK-Q INK-Q left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lnb-git for the clean pytest output-filter enhancement — your ^\S+\.py::\S+\s+PASSED pattern is much safer than greedy .+ matching (avoids ReDoS and avoids folding FAILED ... PASSED lines)!

A few P0/P1 items need to be addressed before merging:

P0 (Must Fix)

  1. Retarget base branch from main to dev (CONTRIBUTING.md):
    • Feature and fix PRs must target dev (only release PRs from dev or urgent hotfix/* target main). Please change the PR base to dev, rebase onto latest origin/dev, and run npm run build.

P1 (Must Fix)

  1. Dot-progress folding gaps (src/utils/output-filter.ts:542):
    • /^\S+\.py\s+\.{3,}(?:\s+\[\s*\d+%\])?$/ requires >= 3 dots, so passing test files with 1–2 tests (tests/test_a.py . [10%], .. [20%]) won't fold and will break contiguous foldable runs. Lowering to \.+ is equally safe since only . is matched (never F/E/x/s).
    • Because dot-progress lines are only in GREEN_BUILD_OR_PASS_PATTERNS (not UNAMBIGUOUS_TEST_PASS_PATTERNS), passing files whose names contain domain words like error, timeout, or failure (e.g. tests/test_error_handling.py .... [ 50%]) get blocked by hasFoldDangerToken and won't fold. Adding the dot-progress regex to UNAMBIGUOUS_TEST_PASS_PATTERNS fixes this safely.
  2. Parametrized verbose pytest node IDs with spaces (src/utils/output-filter.ts:541,562):
    • ^\S+\.py::\S+\s+PASSED misses real pytest -v parametrized lines containing spaces inside [...], e.g. tests/test_api.py::test_parse[hello world] PASSED [ 10%]. Allowing bracketed parameter text (while still ensuring no failure verdict tokens precede PASSED) will cover parametrized suites cleanly.
  3. Generalize pytest E ... root-cause headers (src/utils/output-filter.ts:468):
    • Hardcoding 10 built-in Python exception names misses very common pytest root-cause lines such as E assert 1 == 2, E FileNotFoundError, E ZeroDivisionError, E pydantic.ValidationError, and custom *Error/*Exception classes. Consider generalizing to ^E\s{2,}(?:assert\b|[A-Za-z_][\w.]*(?:Error|Exception)\b).

Checklist

  • Rebase onto origin/dev and change base branch to dev
  • Update dot-progress regex to \.+ and include it in UNAMBIGUOUS_TEST_PASS_PATTERNS
  • Support spaced parametrized [...] node IDs for verbose PASSED lines and generalize ^E\s{2,} root-cause headers
  • Add unit test cases for 1–2 dot files, test_error_*.py ..., spaced [param] PASSED lines, and E assert ... / custom *Error, then run npm run typecheck && npm run build && npm test

@lnb-git
lnb-git force-pushed the feat/pytest-output-filter branch from 6c1afa9 to bd20e3a Compare November 28, 2026 04:54
@lnb-git
lnb-git changed the base branch from main to dev November 28, 2026 04:54
@lnb-git

lnb-git commented Nov 28, 2026

Copy link
Copy Markdown
Author

Thanks @INK-Q for the thorough review! All P0/P1 items have been addressed:

  1. Base branch & rebase: Rebased cleanly onto latest upstream/dev, switched the PR base to dev, and rebuilt dist/mcp-server.mjs.
  2. Pytest dot-progress: Relaxed PYTEST_DOT_PASS_PATTERN to /^\S+\.py\s+\.+(?:\s+\[\s*\d+%\])?$/ and added it to UNAMBIGUOUS_TEST_PASS_PATTERNS so 1–2 dot runs and files like test_error_handling.py .... [ 50%] fold without tripping domain-word guards.
  3. Parametrized verbose PASSED lines: Updated PYTEST_VERBOSE_PASS_PATTERN to accept spaced and single-nested [...] node IDs (e.g. test_parse[hello world] PASSED [ 10%]) in linear time while never matching failure verdicts.
  4. Generalized pytest root-cause headers: Added case-sensitive PYTEST_ROOT_CAUSE_LINE_PATTERN (/^E\s{2,}(?:assert\b|[A-Za-z_][\w.]*(?:Error|Exception)\b)/) plus === FAILURES === / === ERRORS === banners via isRootCauseHeaderLine.
  5. Verification: Added unit tests covering all checklist scenarios (plus adversarial linear-time guard) and verified npm run typecheck, npm run build, sh -n install.sh, npm test (185/185 passed), and npm run validate.

@INK-Q INK-Q left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lnb-git for retargeting dev and addressing the dot-progress and spaced parametrized pytest IDs! Re-review caught two 1-line P1 regex bugs to fix before running CI and merging:

P1 (Must fix)

  1. Quadratic $O(N^2)$ ReDoS backtracking in PYTEST_VERBOSE_PASS_PATTERN (src/utils/output-filter.ts:522-523)

    • /^\S+\.py::[^\s\[]+(?:\[(?:[^\[\]\r\n]|\[[^\[\]\r\n]*\])+\])?\s+PASSED(?:\s+\[\s*\d+%\])?$/ allows both \S+ and [^\s\[]+ to consume .py::, causing quadratic backtracking on non-matching lines with repeated .py:: tokens (verified in Node: "a.py::".repeat(8000) + " FAIL" — 48 KB — takes 233.6 ms, scaling to ~9 s at 300 KB).
    • Fix: Disallow : in the file-path prefix except an optional Windows drive letter: /^(?:[A-Za-z]:)?[^\s:]+\.py::[^\s\[]+.../ (drops the same 48 KB input to 0.18 ms while still matching C:\repo\tests\test_a.py::TestCls::test_ok[a b] PASSED [100%]), and add a repeated-.py:: adversarial test.
  2. PYTEST_ROOT_CAUSE_LINE_PATTERN misses bare E Exception: / E Error: and Python 3.11+ ExceptionGroup (src/utils/output-filter.ts:473)

    • /^E\s{2,}(?:assert\b|[A-Za-z_][\w.]*(?:Error|Exception)\b)/ requires at least 1 character before Error/Exception, so E Exception: boom, E Error: ..., and E ExceptionGroup: ... all return false and miss root-cause header promotion.
    • Fix: Change to /^E\s{2,}(?:assert\b|(?:[A-Za-z_][\w.]*)?(?:Error|Exception)(?:Group)?\b)/ (still rejects E error = 1, E my_error_var = 1, E + where, and lowercase e assert) and add unit test coverage.

P2 (Nice to have)

  • Please update the PR description to match the actual diff (it still mentions collapsing === test session starts === / platform ... / rootdir: / collected N items and matching Traceback / FAILED ...::..., which aren't in the patch).

Checklist

  • Fix P1 #1 (eliminate .py:: quadratic backtracking in PYTEST_VERBOSE_PASS_PATTERN + adversarial test)
  • Fix P1 #2 (match bare E Exception:, E Error:, and ExceptionGroup + unit tests)
  • Rebase onto latest origin/dev (3675109), rebuild dist/mcp-server.mjs (npm run build), and confirm CI passes

@lnb-git
lnb-git force-pushed the feat/pytest-output-filter branch from bd20e3a to ebdd4a6 Compare November 29, 2026 07:41
@lnb-git

lnb-git commented Nov 29, 2026

Copy link
Copy Markdown
Author

Thanks @INK-Q for the re-review and exact ReDoS repro! Rebased cleanly onto latest upstream/dev (4a591ff) and addressed both P1s + P2 in ebdd4a6:

  1. P1 fix(windows): support PowerShell commands with fallback and console codepage decoding #1 (eliminate quadratic .py:: backtracking in PYTEST_VERBOSE_PASS_PATTERN): Restricted the file-path prefix to (?:[A-Za-z]:)?[^\s:]+\.py:: so repeated .py:: tokens fail in linear time while preserving Windows drive-letter paths (C:\repo\tests\test_a.py::TestCls::test_ok[a b] PASSED [ 25%]). Added a 48 KB repeated-.py:: adversarial timing test ("a.py::".repeat(8000) + " FAIL").
  2. P1 feat(read-slices): add Godot GDScript (.gd) outline support #2 (bare Error / Exception / ExceptionGroup): Updated PYTEST_ROOT_CAUSE_LINE_PATTERN to /^E\s{2,}(?:assert\b|(?:[A-Za-z_][\w.]*)?(?:Error|Exception)(?:Group)?\b)/ and added positive tests (E Exception:, E Error:, E ExceptionGroup:) plus negative tests (E error = 1, E my_error_var = 1, E + where, e assert).
  3. P2 (PR description): Updated the PR description to match the exact diff scope.
  4. Verification: Rebuilt dist/mcp-server.mjs and verified npm run typecheck, npm run build && git diff --exit-code -- dist/, sh -n install.sh, npm test (212/212 passed), and npm run validate.

@INK-Q INK-Q left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lnb-git for the quick fixes in ebdd4a6! Re-verified locally and via CI:

  • PYTEST_VERBOSE_PASS_PATTERN stays strictly linear-time across repeated .py::, repeated .py, dot-flood, and nested-bracket adversarial inputs (<4 ms).
  • PYTEST_ROOT_CAUSE_LINE_PATTERN accurately promotes bare Error/Exception/ExceptionGroup headers without false positives on lowercase/non-exception E lines.
  • All 8 CI checks (Linux/macOS/Windows + stress) are green and merging onto latest dev keeps dist/ clean with 0 B schema overhead.

LGTM — merging now!

@INK-Q
INK-Q merged commit 291239e into INK-Q:dev Nov 29, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants